//
//  MDFModelCreateStatus.h
//  CardKing
//
//  Created by tanxk_mini on 2018/11/21.
//  Copyright © 2018 runzezhihun. All rights reserved.
//

static NSString *ClassPrifix = @"CDK";

static NSString *obtionModelFile (NSString *fileName) {  return [NSString stringWithFormat:@"%@%@Model",    ClassPrifix,[fileName capitalizedString]]; }
static NSString *obtionModelFileH(NSString *fileName) {  return [NSString stringWithFormat:@"%@%@Model.h",  ClassPrifix,[fileName capitalizedString]]; }
static NSString *obtionModelFileM(NSString *fileName) {  return [NSString stringWithFormat:@"%@%@Model.m",  ClassPrifix,[fileName capitalizedString]]; }
static NSString *obtionItemFile  (NSString *fileName) {  return [NSString stringWithFormat:@"%@%@Item",     ClassPrifix,[fileName capitalizedString]]; }
static NSString *obtionItemFileH (NSString *fileName) {  return [NSString stringWithFormat:@"%@%@Item.h",   ClassPrifix,[fileName capitalizedString]]; }
static NSString *obtionItemFileM (NSString *fileName) {  return [NSString stringWithFormat:@"%@%@Item.m",   ClassPrifix,[fileName capitalizedString]]; }
static NSString *obtionPortFile  (NSString *fileName) {  return [NSString stringWithFormat:@"%@%@.h",       ClassPrifix,[fileName capitalizedString]]; }
static NSString *obtionPortFileH (NSString *fileName) {  return [NSString stringWithFormat:@"%@%@_h",       ClassPrifix,[fileName capitalizedString]]; }



/**
 生成.h 文件内容

 @param className 类名
 @param superName 父类 默认为NSObject
 @param content 需要填充的内容 imports
 @param imports 需要导入的头文件
 @return 内容
 */
static NSMutableString *obtioFileToInterface(NSString *className,NSString *superName,NSString *content, NSArray<NSString *> *imports){
    
    NSMutableString *string = [NSMutableString stringWithString:@"#import <Foundation/Foundation.h>"];

    [string insertString:[NSString stringWithFormat:@"%@\n\n",@"/// 如果需要自定义字段请用 ‘//custom’"] atIndex:0];
    [imports enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [string appendFormat:@"\n#import \"%@.h\"",obj];
    }];
    [string appendString:@"\n\n"];
    [string appendFormat:@"@interface %@ : %@",className,superName?:@"NSObject"];
    [string appendString:@"\n"];
    [string appendString:content];
    [string appendString:@"\n\n"];
    [string appendString:@"@end"];
    return string;
}

/**
 生成.m 文件内容 仅仅包含实现

 @param className 类名
 @param content 需要填充的内容 isImportSelfName
 @param isImportSelfName 如果不调用 obtioFileToImplementationAndInterface 仅仅调用此方法，需要导入自己的头文件
 @return 内容
 */
static NSMutableString *obtioFileToImplementation(NSString *className,NSString *content, BOOL isImportSelfName){
    
    NSMutableString *string = [NSMutableString string];
    
    if (isImportSelfName == YES) {
        [string appendFormat:@"#import \"%@.h\"",className];
    }
    [string appendString:@"\n\n"];
    [string appendFormat:@"@implementation %@",className];
    
    if (content)
    {
        [string appendString:@"\n\n"];
        [string appendString:content];
    }
    
    [string appendString:@"\n\n"];
    [string appendString:@"@end"];
    
    return string;
}

/**
 生成.m 文件内容 包含声明和实现

 @param className 类名
 @param content_h 声明需要填充的内容
 @param content_m 实现需要填充的内容
 @param imports   需要导入的头文件
 @return 内容
 */
static NSMutableString *obtioFileToImplementationAndInterface(NSString *className,NSString *content_h,NSString *content_m, NSArray<NSString *> *imports){
    
    NSMutableString *string = [NSMutableString stringWithFormat:@"#import \"%@.h\"",className];
    
    [imports enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [string appendString:@"\n"];
        [string appendFormat:@"#import \"%@.h\"",obj];
    }];
    
    [string appendString:@"\n\n"];
    [string appendFormat:@"@interface %@ ()",className];
    if (content_h) {
        [string appendString:@"\n\n"];
        [string appendString:content_h];
    }
    [string appendString:@"\n\n"];
    [string appendString:@"@end"];
    [string appendString:obtioFileToImplementation(className,content_m, NO)];
    
    return string;
}

